import { BblAttach } from "../entity/attach.entity";
import { BblRecord } from "../entity/record.entity";
import { AttachDto } from "./att.dto";
import { utils } from "../utils";

export class RecordCreateDto {
  /**
   * 球杆编号
   */
  recordCode: string;
  /**
   * 球杆品牌
   */
  recordBrand: string;
  /**
   * 球杆重量
   */
  recordWeight: string;
  /**
   * 球杆长度
   */
  recordLength: string;
  /**
   * 球杆重心
   */
  recordCenter: string;
  /**
   * 杆头直径
   */
  recordTopDiam: string;
  /**
   * 握把直径
   */
  recordTailDiam: string;
  /**
   * 球杆主图id
   */
  recordMainImgIds: string[];
  /**
   * 档案描述
   */
  recordText: string;

  static toRecord(dto: RecordCreateDto) {
    const record = new BblRecord();
    record.recordCode = dto.recordCode;
    record.recordBrand = dto.recordBrand;
    record.recordWeight = dto.recordWeight;
    record.recordLength = dto.recordLength;
    record.recordCenter = dto.recordCenter;
    record.recordTopDiam = dto.recordTopDiam;
    record.recordTailDiam = dto.recordTailDiam;
    record.recordText = dto.recordText;
    record.recordMainImgs = dto.recordMainImgIds.map((d) => {
      const att = new BblAttach();
      att.attId = d;
      return att;
    });
    record.recordId = utils.uuid();
    return record;
  }
}

export class RecordUpdateDto {
  /**
   * 球杆编号
   */
  recordCode: string;
  /**
   * 球杆品牌
   */
  recordBrand: string;
  /**
   * 球杆重量
   */
  recordWeight: string;
  /**
   * 球杆长度
   */
  recordLength: string;
  /**
   * 球杆重心
   */
  recordCenter: string;
  /**
   * 杆头直径
   */
  recordTopDiam: string;

  /**
   * 握把直径
   */
  recordTailDiam: string;

  /**
   * 档案主图
   */
  recordMainImgIds: string[];
  /**
   * 档案描述
   */
  recordText: string;
}

export class RecordPageQueryDto {
  recordCode: string;
  recordBrand: string;
  current: number;
  pageSize: number;
}

export class RecordDto {
  /**
   * 档案id
   */
  recordId: string;
  /**
   * 球杆编号
   */
  recordCode: string;
  /**
   * 球杆品牌
   */
  recordBrand: string;
  /**
   * 球杆重量
   */
  recordWeight: string;
  /**
   * 球杆长度
   */
  recordLength: string;
  /**
   * 球杆重心
   */
  recordCenter: string;
  /**
   * 杆头直径
   */
  recordTopDiam: string;

  /**
   * 握把直径
   */
  recordTailDiam: string;

  /**
   * 档案主图
   */
  recordMainImgs: AttachDto[];
  /**
   * 档案描述
   */
  recordText: string;
  /**
   * 创建时间
   */
  createAt: number;

  static from(record: BblRecord) {
    const dto = new RecordDto();
    dto.recordId = record.recordId;
    dto.recordCode = record.recordCode;
    dto.recordBrand = record.recordBrand;
    dto.recordWeight = record.recordWeight;
    dto.recordLength = record.recordLength;
    dto.recordCenter = record.recordCenter;
    dto.recordTopDiam = record.recordTopDiam;
    dto.recordTailDiam = record.recordTailDiam;
    dto.recordMainImgs = record.recordMainImgs.map((d) => {
      const att = new AttachDto(d);
      return att;
    });
    dto.recordText = record.recordText;
    dto.createAt = record.createAt.valueOf();
    return dto;
  }
}
